import {Component, OnInit} from "@angular/core";
import {PersonalProgectInformation} from "../entity/PersonalProgectInformation";
import {UserService} from "../service/user.service";
import {Router, ActivatedRoute, Params} from "@angular/router";
import {Page} from "../../shared/entity/Page";
@Component({
  selector:"personal-join",
  templateUrl:'./personal-join.html',

})
export class PersonalJoinComponent implements OnInit{
  public personalJoinMessage:Array<PersonalProgectInformation>;
  public page:Page<PersonalProgectInformation> = new Page<PersonalProgectInformation>();
  private currentUserId:string;
  constructor(private  userservice :UserService,public router:Router,private activatedRouter: ActivatedRoute){}
  // private getPersoanlJoinMessage(userid:string){
  //   //noinspection TypeScriptUnresolvedFunction
  //   this.userservice.getPersonalJoinMessage(userid)
  //     .then(personalJoinMessage=>this.personalJoinMessage=personalJoinMessage)
  // }
  public toProjectIndex(id:string){

    this.router.navigate(['/project/index/',id]);
  }
  // private initParam(param: any):Promise<string> {
  //   this.getPersoanlJoinMessage(param);
  //   return param;
  // }
  ngOnInit(){
    this.activatedRouter.params
    // (+) converts string 'id' to a number
      .switchMap((params: Params) =>
        this.userservice.getPersonalJoinMessage(this.currentUserId=params["id"],params["pageNo"]))
      .subscribe((page: Page<PersonalProgectInformation>)=>{
        this.page = page;
     });
  }

  public setPage(pageNo:string){
    this.router.navigate(['/personal/personalJoin/',{id:this.currentUserId+"", pageNo: pageNo}]);
  }
}
